{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Gauss-Newton"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 8,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "import scipy as sp\n",
        "import matplotlib.pyplot as pt\n",
        "import scipy.linalg as la"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "We would like to fit the model $f(t) = x_0 e^{x_1 t}$ to the following data using Gauss-Newton:"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 13,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "t = np.array([0.0, 1.0, 2.0, 3.0])\n",
        "y = np.array([2.0, 0.7, 0.3, 0.1])"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "First, define a residual function (as a function of $\\mathbf x=(x_0, x_1)$)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 14,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "def residual(x):\n",
        "    return y - x[0] * np.exp(x[1] * t)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Next, define its Jacobian matrix:"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 15,
      "metadata": {
        "collapsed": true
      },
      "outputs": [],
      "source": [
        "def jacobian(x):\n",
        "    return np.array([\n",
        "        -np.exp(x[1] * t),\n",
        "        -x[0] * t * np.exp(x[1] * t)\n",
        "        ]).T"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Here are two initial guesses. Try both:"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 56,
      "metadata": {
        "collapsed": true
      },
      "outputs": [],
      "source": [
        "#x = np.array([1, 0])\n",
        "x = np.array([0.4, 2])"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Here's a plotting function to judge the quality of our guess:"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 57,
      "metadata": {
        "collapsed": false
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Residual norm: 162.72704101675862\n"
          ]
        },
        {
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEACAYAAAC08h1NAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XmcFOW1//HPAWYEUZAlIoriBooLoqho9GrHNeJC3NAY\n1xhjjIkYX9FgvFdGk59RsxhNfphcJS5EwAUQMCCo2EZUUNERkT0aNnVQWYwCzgxz7h9PDwzjDNMz\nXT3VPf19v1716urq6urTFHPq6VNPPWXujoiIFI5WcQcgIiLNS4lfRKTAKPGLiBQYJX4RkQKjxC8i\nUmCU+EVECkyDid/MRphZmZnNqbHsEDN7zczeNrPXzeyIGq/dZ2aLzazUzPplK3AREWmadFr8DwGn\n1lp2NzDM3Q8FhqWeY2YDgX3cvRdwNfCXCGMVEZEINJj43X0GsKbW4iqgY2p+J2Blav4s4NHU+2YB\nHc2sWzShiohIFNo08X0/A6aa2e8BA76ZWr4bsLzGeitTy8qaHKGIiESqqSd3rwGGuPsehIPA31LL\nrY51NSaEiEgOaWqL/zJ3HwLg7k+Z2YOp5SuA3Wus1wP4sK4NmJkOCCIiTeDudTWy05Zui9/YujW/\n0syOBzCzE4HFqeUTgUtTy48C1rp7vWUed2+x07Bhw2KPQd9P36/QvlshfL8oNNjiN7NRQALoYmbL\nCL14rgLuM7PWwEbgh6lEPtnMBprZEuBL4IpIohQRkcg0mPjd/aJ6Xjq8nvV/klFEIiKSVbpyN0sS\niUTcIWSVvl/+asnfDVr+94uCRVUzavQHm3lcny0ikq/MDG+mk7siItJCKPGLiBQYJX4RkQKjxC8i\nUmCU+EVECowSv4hIgVHiFxEpMEr8IiIFRolfRKTAKPGLiBQYJX4RkQKjxC8iUmCU+EVECowSv4hI\ngWkw8ZvZCDMrM7M5tZb/1MwWmNm7ZnZnjeU3m9liM5tvZq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text/plain": [
              "<matplotlib.figure.Figure at 0x7f2bac6693c8>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "def plot_guess(x):\n",
        "    pt.plot(t, y, 'ro', markersize=20, clip_on=False)\n",
        "    T = np.linspace(t.min(), t.max(), 100)\n",
        "    Y = x[0] * np.exp(x[1] * T)\n",
        "    pt.plot(T, Y, 'b-')\n",
        "    \n",
        "    print(\"Residual norm:\", la.norm(residual(x), 2))\n",
        "\n",
        "plot_guess(x)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Code up one iteration of Gauss-Newton. Use `numpy.linalg.lstsq()` to solve the least-squares problem, noting that that function returns a tuple--the first entry of which is the desired solution.\n",
        "\n",
        "Also print the residual norm. Use `plot_iterate` to visualize the current guess.\n",
        "\n",
        "Then evaluate this cell in-place many times (Ctrl-Enter):"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 79,
      "metadata": {
        "collapsed": false
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Residual norm: 0.044677532987197045\n"
          ]
        },
        {
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXsAAAEFCAYAAAACFke6AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl0VdXZx/HvzsRQFeuEEPICMshgmaIkCGhqVcZKoQpO\ndagVXl4HlKI4FAlap2oVrboUFOuMYINTQMRqVMCkEkBkkMlCA4QgCnXAmNyw3z/2DYSQ4Sa5N+cO\nv89aZ+Vezrknz1mH9dydffZ+trHWIiIi0S3O6wBERCT0lOxFRGKAkr2ISAxQshcRiQFK9iIiMUDJ\nXkQkBiSE8uTGmIS2MLIlDDsBWjeFxGIo3QU7iiB7K8yz1vpCGYOIiIAJxTh7Y0x8L5h6Coz8A3Q+\nHZISK+wvBZZCydOwYTXMWwnTrLVlQQ9ERESAECT7psa06Q9zHoJTe0Jibcd/BqUTYd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/oA2w/kobf1cAAAAASUVORK5CYII=\n",
            "text/plain": [
              "<matplotlib.figure.Figure at 0x7f2bac4cc978>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "x = x + la.lstsq(jacobian(x), -residual(x))[0]\n",
        "\n",
        "plot_guess(x)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": true
      },
      "outputs": [],
      "source": []
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.5.1+"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}